package xyz.talentboy.common.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import xyz.talentboy.common.bean.ResponseAccessToken;

@Component
public class AccessUtil {
	
	@Value("${accessTokenUrl}")
	private String url;
	
	@Autowired
	RestTemplate restTemplate;
		
	/**
	 * 获取 accessToken
	 * @return
	 */
	public String getAccessToken(){
		ResponseEntity<ResponseAccessToken> responseEntity = restTemplate.getForEntity(url, ResponseAccessToken.class);
		ResponseAccessToken responseAccessToken = responseEntity.getBody();
		return responseAccessToken.getAccess_token();
	}
	
}
